<?php
include '../base/validateAdminLogin.php';
include '../class/MMysql.php';

$agent_id = $_GET['agent_id'];

$mysql = new MMysql();

$agent = $mysql
    ->where(array('agent_id'=>$agent_id,'del_flag'=>0))
    ->select('agent');
//
$count1=$mysql->where(array('property_category'=>0,'property_agent_id'=>$agent_id,"del_flag"=>0))->count('property');
$count2=$mysql->where(array('property_category'=>1,'property_agent_id'=>$agent_id,"del_flag"=>0))->count('property');
$count3=$mysql->where(array('property_category'=>2,'property_agent_id'=>$agent_id,"del_flag"=>0))->count('property');
?>

<?php
include '../base/layout.php';
?>
<link href="../public/bootstrap-table/dist/bootstrap-table.css" rel="stylesheet" type="text/css" />
<script src="../public/bootstrap-table/dist/bootstrap-table.js"></script>

<style>
    .total{
        background-color:rgb(56,160,188);
        width: 100%;
        height: 34px;
        position: relative;
        top:10px;
        margin-left: 10px;
    }
    .mytab{
        margin-top: 40px;
        margin-left: 10px;
    }
    .tablelist{
        margin-left: 20px;
        margin-right: 30px;
        margin-top: 20px;
    }
</style>


<body>

<?php
include '../base/header.php';
?>

<section style="width: 100%;">

    <?php
    include '../base/sidemenu.php';
    ?>

    <aside class="content">

        <div style="margin-top: 20px;margin-left: 40px;position: relative;">

            <div style="height: 20px;">

            </div>

            <span style="font-size: 40px;">
                Agent edit
            </span>

            <div style="margin-top: 15px;">
                <span class="user_info_span">
                   The company full name
                </span>
                <?php
                echo ' <input class="user_info_input" id="agent_name" type="text" value="'.$agent[0]['agent_name'].'">';
                ?>

            </div>

            <div style="margin-top: 15px;">
                <span class="user_info_span">
                   Tel
                </span>
                <?php
                echo '<input class="user_info_input" id="agent_tel" type="text" value="'.$agent[0]['agent_tel'].'">';
                ?>


            </div>

            <div style="margin-top: 15px;">
                <span class="user_info_span">
                    Email
                </span>
                <?php
                echo ' <input class="user_info_input" id="agent_email" type="text" value="'.$agent[0]['agent_email'].'">';
                ?>


            </div>

            <div style="margin-top: 15px;">
                <span class="user_info_span">
                   Initial Password
                </span>
                <?php
                echo '<input class="user_info_input" id="agent_password" type="text" value="'.$agent[0]['agent_password'].'">';
                ?>
            </div>

            <div style="margin-top: 40px;margin-left: 100px;">
                <button class="btn" id="btnedit" style="background-color: #2B2B2B;color:white;width: 100px;margin-left: 100px;">
                    Confirm
                </button>
            </div>

            <?php
            echo '<input id="agent_id" type="hidden" value="'.$agent[0]['agent_id'].'">';
            ?>

        </div>

    </aside>

</section>

</body>
</html>

<script type="text/javascript">
    $(function () {

        $(".menu").height($('.content').height());

        $("#btnedit").click(function () {

            var agent_name=$("#agent_name").val();
            var agent_tel=$("#agent_tel").val();
            var agent_email=$("#agent_email").val();
            var agent_password=$("#agent_password").val();
            if(agent_name.trim()==""){
                alert(' agent name is not null ');
                return;
            }
            if(agent_tel.trim()==""){
                alert(' agent tel is not null ');
                return;
            }
            if(agent_email.trim()==""){
                alert(' agent email is not null ');
                return;
            }
            if(agent_password.trim()==""){
                alert(' agent password is not null ');
                return;
            }
            $.ajax( {
                url: '../class/agent/agentfunction.php',
                data:{
                    method:'update',
                    agent_name : agent_name,
                    agent_tel : agent_tel,
                    agent_email : agent_email,
                    agent_password : agent_password,
                    agent_id:$("#agent_id").val()
                },
                type:'post',
                success:function(data) {
                    if(data==1){
                        window.wxc.xcConfirm("edit success", window.wxc.xcConfirm.typeEnum.success,{
                                onOk:function(v){
                                window.location.href="agent_list.php";
                                }
                        });
                    }
                },
                beforeSend: function(){

                },
                error : function() {
                    // view("异常！");
                    window.wxc.xcConfirm('edit error', window.wxc.xcConfirm.typeEnum.error);
                }
            });
        });

    });
</script>
